<?php
//============================================================+
// File name   : example_001.php
// Begin       : 2008-03-04
// Last Update : 2010-08-14
//
// Description : Example 001 for TCPDF class
//               Default Header and Footer
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com s.r.l.
//               Via Della Pace, 11
//               09044 Quartucciu (CA)
//               ITALY
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Default Header and Footer
 * @author Nicola Asuni
 * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
 * @link http://tcpdf.org
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
 * @since 2008-03-04
 */

App::import('Vendor','tcpdf/config/lang/eng');
App::import('Vendor','tcpdf'); 

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Sylwester Kowal (21w.pl)');
$pdf->SetTitle('Cleaning Service');
$pdf->SetSubject(__("Wykaz zlecen za wybrany okres wg miejsca realizacji",true));
$pdf->SetKeywords('cleaning, service');

// set default header data
$pdf->SetHeaderData(false, null, __("Wykaz zlecen za wybrany okres wg miejsca realizacji",true), 'from date '.$session->read('Reports.date_from'). ' to '. $session->read('Reports.date_to'));

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
//$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusanscondensed', '', 12, '', true);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage('','LETTER');


$html = '<div class="orders index">
			<h1>'.__("Orders",true).'</h1>
			<table cellpadding="5" cellspacing="0" border="1">
			<tr>
					<th width="30%" >'.__("Order info",true).'</th>
					<th width="30%" >'.__("Customer Address",true).'</th>
					<th width="15%">'.__("Day",true).'</th>
					<th width="25%">'.__("Employees",true).'</th>
			</tr>';

			$i = 0;
			foreach ($orders as $orders_id => $order){
				$class = null;
				if ($i++ % 2 == 0) {
					$class = ' style="background-color:#eeeeee;"';
				}

$html .= 	'<tr'.$class.'>
				<td width="30%" valign="top" align="left">
					'.$order['Order']['numer'].'<br/>
					'.$order['TypesOfSpaces']['name'].' '.$order['TypeOfService']['name'].'<br/>
					'.$order['Order']['estimated_execution_time'].' '.__("hours",	true).'<br/>
					'.$order['Order']['value_of_the_order'].' '.__("USD",	true).'<br/>
					'.$typeOfCycles[$order['OrdersCycle']['type_of_cycle_id']].' x '. $order['OrdersCycle']['repeat'].'
				</td>	
				<td width="30%" valign="top" align="left">
					'.$order['Customer']['name'].' '.$order['Customer']['surname'].'<br/>
					'.$order['Customer']['address1'].' '.$order['Customer']['address2'].'<br/>
					'.$order['Customer']['address3'].' '.$order['Customer']['address4'].'<br/>
					'.__("Phone",true).' '.$order['Customer']['phone1'].'				
				</td>	
				<td width="15%" valign="top" align="left">';

				foreach ($order['Terms'] as $date => $date_value){
					$html .= $time->format("m-d-Y",$date).'<br/>';
				}
$rozdziel_orders = (count($order['Employees']) == 1)?"":'class="rozdziel_orderse"';
$class____ = "";	
$k = 0;			
$html .= 		'</td>	
				<td width="25%" valign="top">
		
					<table cellpadding="0" cellspacing="0">';
						foreach ($order['Employees'] as $employee_id => $employee){
							$class___ = null;
							if ($k++ % 2 == 0) {
								$class___ = ' style="background-color:#ffffff;"';
							}									
$html .= 		'		<tr'.$class___.'>
							<td>
								'.$employee['name'].' '.$employee['surname'].'
							</td>
						</tr>';
						}
$html .= 		'	</table>
				</td>
			</tr>';
		}
$html .= '</table>
		</div>';



// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$data = date('YmdHis');
$pdf->Output("cleaning_service_{$data}.pdf", 'I');
//============================================================+
// END OF FILE
//============================================================+